<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<meta name="keywords" content="">
<meta name="description" content="">
<title>数据内容列表</title>
<link rel="Bookmark" href="/favicon.ico" >
<link rel="Shortcut Icon" href="/favicon.ico" />
<link rel="stylesheet" type="text/css" href="../static/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="../lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="../static/h-ui.admin/css/style.css" />
</head>

<body>
<!--_header 作为公共模版分离出去-->
<header class="navbar-wrapper" id="header">
    
</header>
<!--/_header 作为公共模版分离出去--> 

<!--_menu 作为公共模版分离出去-->
<aside class="Hui-aside" id="menu">
</aside>
<div class="dislpayArrow hidden-xs"> <a class="pngfix" href="javascript:void(0);" onClick="displaynavbar(this)"></a> </div>
<!--/_menu 作为公共模版分离出去-->

<section class="Hui-article-box">
    <nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> <a href="../index.html" class="maincolor">首页</a>
        <span class="c-gray en">&gt;</span>
        数据内容列表
        <span class="c-gray en">&gt;</span>
        <span id="mbx"></span>
        
        <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a> </nav>
    <div class="Hui-article">
        <article class="cl pd-20">
            <div class="text-c">
                <span class="select-box inline text-l">
                    <select name="" id="sel_option" class="select" style="width: 400px;">

                    </select>
                </span>
                <!-- <input type="text" onfocus="WdatePicker({maxDate:'#F{$dp.$D(\'datemax\')||\'%y-%M-%d\'}'})" id="datemin" class="input-text Wdate" style="width:120px;">
                -
                <input type="text" onfocus="WdatePicker({minDate:'#F{$dp.$D(\'datemin\')}',maxDate:'%y-%M-%d'})" id="datemax" class="input-text Wdate" style="width:120px;">
                <input type="text" class="input-text" style="width:250px" placeholder="输入管理员名称" id="" name=""> -->
                <!-- <button type="submit" class="btn btn-success" id="" name=""><i class="Hui-iconfont">&#xe665;</i>确定</button> -->
            </div>
            <div class="cl pd-5 bg-1 bk-gray mt-20" style="min-width: 800px;max-width: 90%;">
                <span class="l">
                    <!-- <a href="javascript:;" onclick="datadel()" class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量删除</a> -->
                    <a href="javascript:;" onclick="edata_add('添加数据','add.html','800','500')" class="btn btn-primary radius"><i class="Hui-iconfont">&#xe600;</i> 添加数据</a>
                </span>
                <span class="r">共有数据：<strong id="total"></strong> 条</span>
            </div>
            <div id="edatalist" style="min-width: 800px;max-width: 90%;">
                <table class="table table-border table-bordered table-bg">
                    <thead>
                        <tr class="text-c">
                            <th width="40px;"><input type="checkbox" name="" value=""></th>
                            <th width="80px;">ID</th>
                            <th style="min-width: 200px;">标题</th>
                            <th width="160px;">发布者</th>
                            <th width="180px;">发布时间</th>
                            <th width="140px;">点击量</th>
                            <th width="200px;">操作</th>
                        </tr>
                    </thead>
                    <tbody id="liebiao_box">

                    </tbody>
                </table>
                <div class="dataTables_wrapper no-footer" id="fanye">
                    <!-- <div class="dataTables_info" id="DataTables_Table_0_info" role="status" aria-live="polite">显示 1 到 2 ，共 2 条</div>
                    <div class="dataTables_paginate paging_simple_numbers" id="DataTables_Table_0_paginate">
                        <a class="paginate_button previous disabled" aria-controls="DataTables_Table_0" data-dt-idx="0" tabindex="0" id="DataTables_Table_0_previous">上一页</a>
                        <span><a class="paginate_button current" aria-controls="DataTables_Table_0" data-dt-idx="1" tabindex="0">1</a></span>
                        <a class="paginate_button next disabled" aria-controls="DataTables_Table_0" data-dt-idx="2" tabindex="0" id="DataTables_Table_0_next">下一页</a>
                    </div> -->
                </div>
            </div>
        </article>
    </div>
</section>

<!--_footer 作为公共模版分离出去--> 
<script type="text/javascript" src="../lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="../lib/layer/2.4/layer.js"></script> 
<script type="text/javascript" src="../static/h-ui/js/H-ui.js"></script> 
<script type="text/javascript" src="../static/h-ui.admin/js/H-ui.admin.page.js"></script> 
<!--/_footer /作为公共模版分离出去--> 

<script  type="text/javascript" src="../static/js/admin.js"></script>
<script  type="text/javascript" src="../static/js/header.js?123"></script>
<script  type="text/javascript" src="../static/js/menu.js?1234"></script>

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="../lib/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" src="../lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="../lib/laypage/1.2/laypage.js"></script> 
<script type="text/javascript">
// 获取url上的 classid 
    var classid = 0;
    var page = 0;
    var query = window.location.search.substring(1);
    var vars = query.split("&");
    for (var i = 0; i < vars.length; i++) {
        var pair = vars[i].split("=");
        if (pair[0] == "classid") {
            classid = parseInt(pair[1]);
        }
        if (pair[0] == "page") {
            page = parseInt(pair[1]);
        }
    }
    if (page <= 0) {
        page = 1;
    }

    $.ajax({
        url: "/ajax/class/getdataclasstree",
        type: "GET",
        data: null,
        beforeSend:function(request){
            request.setRequestHeader("authStr", window.localStorage.getItem("userId")+"-"+window.localStorage.getItem("token"));
        },
        success: function (data) {
            if (data.success == true) {
                // console.log(data.data);
                edataclasslist = data.data;
                var option_str = '<option value="0">--请选栏目--</option>';
                edataclasslist.forEach(eclass => {
                    // console.log(eclass.children);
                    if (classid==eclass.id) {
                        option_str += '<option value="'+eclass.id+'" selected>'+eclass.classname+'</option>';
                    } else {
                        option_str += '<option value="'+eclass.id+'">'+eclass.classname+'</option>';
                    }
                    eclass.children.forEach(function(ecl){
                        // console.log(ecl);
                        if (classid==ecl.id) {
                            option_str += '<option value="'+ecl.id+'" selected>&nbsp;&nbsp;&nbsp;&nbsp;├'+ecl.classname+'</option>';
                        } else {
                            option_str += '<option value="'+ecl.id+'">&nbsp;&nbsp;&nbsp;&nbsp;├'+ecl.classname+'</option>';
                        }
                        ecl.children.forEach(function(e){
                            // console.log(ecl);
                            if (classid==e.id) {
                                option_str += '<option value="'+e.id+'" selected>&nbsp;&nbsp;&nbsp;&nbsp;└--'+e.classname+'</option>';
                            } else {
                                option_str += '<option value="'+e.id+'">&nbsp;&nbsp;&nbsp;&nbsp;└--'+e.classname+'</option>';
                            }
                        
                        });
                    });
                });
                $("#sel_option").append(option_str);
            }
        }
    });

    //
    // if (classid == 0) {
    //     // $("#edatalist").append("<h2 class='text-c'>请选择数据表</h2>");
    // } else {

    // }
        $.ajax({
            type: "get",
            url: '/ajax/edata/list',
            data: {
                "classid": classid,
                "page": page
            },
            dataType: "json",
            success: function (data) {
                if (data.success == true) {
                    // console.log(data.data.total);
                    // console.log(data.data);
                    // 导航栏
                    if (classid == 0) {
                        $("#mbx").html('新闻表(news)');
                    } else {
                        $("#mbx").html(data.data.classInfo.classname+'('+data.data.classInfo.tablename+')');
                    }

                    var total = data.data.total;
                    $("#total").text(total);

                    var liebiao_str = ""; 
                    data.data.list.forEach(elist => {
                        liebiao_str += '<tr class="text-c">';
                        liebiao_str += '<td><input type="checkbox" value="'+elist.id+'" name=""></td>';
                        liebiao_str += '<td>'+elist.id+'</td>';
                        liebiao_str += '<td class="text-l">'+elist.title+'</td>';
                        liebiao_str += '<td>'+elist.username+'</td>';
                        liebiao_str += '<td>'+ formatDate(elist.newstime)+'</td>';
                        liebiao_str += '<td>'+elist.onclick+'</td>';
                        liebiao_str += '<td class="td-manage">';
                        liebiao_str += '<a title="编辑" href="javascript:;" onclick="eadta_edit(\'数据编辑\',\'add.html\','+elist.id+',\'800\',\'500\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6df;</i></a>';
                        liebiao_str += '<a title="删除" href="javascript:;" onclick="edata_del(this,\''+elist.id+'\')" class="ml-5" style="text-decoration:none"><i class="Hui-iconfont">&#xe6e2;</i></a>';
                        liebiao_str += '</td>>';
                        liebiao_str += '</tr>';
                    });
                    $("#liebiao_box").append(liebiao_str);

                    var fanye_str = "";
                    var pages = Math.ceil(total / 15);

                    fanye_str += '<div class="dataTables_info" id="DataTables_Table_0_info" role="status" aria-live="polite"><span>总数:' + total +'&nbsp;&nbsp;每页:15&nbsp;共:'+ pages + '页</span></div>';
                    fanye_str += ' <div class="dataTables_paginate paging_simple_numbers">';
                    if (page == 1) {
                        // fanye_str += '<a class="paginate_button previous disabled">首页</a>';
                        fanye_str += '<a class="paginate_button previous disabled">上一页</a>';
                    } else {
                        // fanye_str += '<a class="paginate_button previous disabled" href="/console/edata/list.html?classid=' + classid + '&page=1">首页</a>&nbsp;&nbsp;';
                        fanye_str += '<a class="paginate_button previous disabled" href="/console/edata/list.html?classid=' + classid + '&page=' + (page - 1) + '">上一页</a>&nbsp;&nbsp;';
                    }
                    for (let i = 0; i < pages; i++) {
                        fanye_str += '<span><a class="paginate_button '+(i+1==page?"current":"")+'" href="/console/edata/list.html?classid=' + classid + '&page=' + (i+1) + '">'+(i+1)+'</a></span>';
                    }
                    if (page >= pages) {
                        fanye_str += '<a class="paginate_button next disabled">下一页</a>';
                        // fanye_str += '<a class="paginate_button next disabled">尾页</a>';
                    } else {
                        fanye_str += '<a class="paginate_button next disabled" href="/console/edata/list.html?classid=' + classid + '&page=' + (page + 1) + '">下一页</a>';
                        // fanye_str += '<a class="paginate_button next disabled" href="/console/edata/list.html?classid=' + 0 + '&page=' + pages + '">尾页</a>';
                    }
                    fanye_str += '</div>';

                    $("#fanye").append(fanye_str);
                } else {
                    $("#edatalist").append("<h2 class='text-c'>数据表不存在</h2>");
                }
            }
        });

    $("#sel_option").on("change", function(){
        var class_id = $("#sel_option option:selected").val();
        // var table_name = $("#sel_option option:selected").data("tablename");
        // console.log(tablename);
        console.log(class_id);

        if(classid != class_id){
            self.location.href='/console/edata/list.html?classid='+class_id;
        }
    })

    /*
        参数解释：
        title	标题
        url		请求的url
        id		需要操作的数据id
        w		弹出层宽度（缺省调默认值）
        h		弹出层高度（缺省调默认值）
    */

    /*编辑数据-编辑*/
    function eadta_edit(title,url,id,w,h){
        // console.log(id);
        // console.log(classid);
        if (id==null || classid==0) {
            layer.msg('请选择栏目', {icon: 5, time:2000});
            return false;
        } else {
            if (classid==246|| classid==247|| classid==248) {   // photo 表
                // window.location.href= 'photo.html?action=add&classid='+classid;
                url= 'photo.html?action=edit&id='+id+'&classid='+classid;
                w = parseInt(w) + 200;
                // console.log(w);
            } else {
                url = url+'?action=edit&id='+id+'&classid='+classid;
            }
            layer_show(title,url,w,h);
        }
    }

    /*编辑数据-增加*/
    function edata_add(title,url,w,h){
        if (classid==0) {
            layer.msg('请选择数据表', {icon: 5, time:2000});
            return false;
        } else {
            // console.log(classid);
            if (classid==246|| classid==247|| classid==248) {   // photo 表
                // window.location.href= 'photo.html?action=add&classid='+classid;
                url= 'photo.html?action=add&classid='+classid;
                w = parseInt(w) + 200;
                // console.log(w);
            } else {
                url = url+'?action=add&classid='+classid;
            }
            layer_show(title,url,w,h);
        }
    }

    /*编辑数据-删除*/
    function edata_del(obj, id){
        layer.confirm('确认要删除吗？',function(index){
            //此处请求后台程序，下方是成功后的前台处理……
            $.ajax({
                type:"POST",
                url:"/ajax/edata/delete",
                data:{"id":id, "classid":classid},
                dataType:"json",
                beforeSend:function(request){
                    request.setRequestHeader("authStr", window.localStorage.getItem("userId")+"-"+window.localStorage.getItem("token"));
                },
                success:function(data){
                    if(data.success==true){                       
                        $(obj).parents("tr").remove();
                        layer.msg('已删除!',{icon:1, time:1000});
                    } else{
                        layer.msg(data.msg,{icon:5, time:1000});
                    }
                    return false;
                },
                error:function(e){
                    layer.msg("操作出错, 请稍后重试",{icon:5, time:1000})
                }
            });
        });
    }
</script> 
<!--/请在上方写此页面业务相关的脚本-->
</body>
</html>